]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
grabHelper: Only connect to specific signals when actually taking a grab
authorJasper St. Pierre <jstpierre@mecheye.net>
Mon, 20 Aug 2012 00:50:34 +0000 (20:50 -0400)
committerJasper St. Pierre <jstpierre@mecheye.net>
Mon, 20 Aug 2012 01:15:50 +0000 (21:15 -0400)
When we enter the overview, we don't explicitly don't take a grab, so we
shouldn't connect to key-focus-changed and things like that, otherwise
random overview code will drop our grab for us.

This fixes escape in the overview not dropping when a notification is up.

js/ui/grabHelper.js

index a12e0ad8f6b7feaa98125b4f94f1c762da7392d2..8b04dbdad3a1e5253578160a3a21f72f73a75ddf 100644 (file)
@@ -46,6 +46,7 @@ const GrabHelper = new Lang.Class({
         this._ignoreRelease = false;
 
         this._modalCount = 0;
+        this._grabFocusCount = 0;
     },
 
     // addActor:
@@ -145,7 +146,7 @@ const GrabHelper = new Lang.Class({
         if (this.isActorGrabbed(params.actor))
             return;
 
-        if (this._grabStack.length == 0)
+        if (this._grabFocusCount == 0 && this._modalCount == 0)
             this._fullGrab(hadFocus, params.modal, params.grabFocus);
 
         params.savedFocus = focus;
@@ -154,6 +155,9 @@ const GrabHelper = new Lang.Class({
         if (params.modal)
             this._modalCount++;
 
+        if (params.grabFocus)
+            this._grabFocusCount++;
+
         _navigateActor(newFocus, hadFocus);
     },
 
@@ -176,10 +180,12 @@ const GrabHelper = new Lang.Class({
             }
         }
 
-        this._capturedEventId = global.stage.connect('captured-event', Lang.bind(this, this._onCapturedEvent));
-        this._eventId = global.stage.connect('event', Lang.bind(this, this._onEvent));
-        this._keyFocusNotifyId = global.stage.connect('notify::key-focus', Lang.bind(this, this._onKeyFocusChanged));
-        this._focusWindowChangedId = metaDisplay.connect('notify::focus-window', Lang.bind(this, this._focusWindowChanged));
+        if (modal || grabFocus) {
+            this._capturedEventId = global.stage.connect('captured-event', Lang.bind(this, this._onCapturedEvent));
+            this._eventId = global.stage.connect('event', Lang.bind(this, this._onEvent));
+            this._keyFocusNotifyId = global.stage.connect('notify::key-focus', Lang.bind(this, this._onKeyFocusChanged));
+            this._focusWindowChangedId = metaDisplay.connect('notify::focus-window', Lang.bind(this, this._focusWindowChanged));
+        }
     },
 
     // ignoreRelease:
@@ -220,13 +226,15 @@ const GrabHelper = new Lang.Class({
 
             if (poppedGrab.modal)
                 this._modalCount--;
+
+            if (poppedGrab.grabFocus)
+                this._grabFocusCount--;
         }
 
         let focus = global.stage.key_focus;
         let hadFocus = focus && this._isWithinGrabbedActor(focus);
 
-        // If we took away the last grab, ungrab ourselves.
-        if (this._grabStack.length == 0)
+        if (this._grabFocusCount == 0 && this._modalCount == 0)
             this._fullUngrab(wasModal);
 
         let poppedGrab = poppedGrabs[0];
@@ -234,15 +242,26 @@ const GrabHelper = new Lang.Class({
     },
 
     _fullUngrab: function(wasModal) {
-        global.stage.disconnect(this._capturedEventId);
-        this._capturedEventId = 0;
-        global.stage.disconnect(this._eventId);
-        this._eventId = 0;
-        global.stage.disconnect(this._keyFocusNotifyId);
-        this._keyFocusNotifyId = 0;
-        let metaDisplay = global.screen.get_display();
-        metaDisplay.disconnect(this._focusWindowChangedId);
-        this._focusWindowChangedId = 0;
+        if (this._capturedEventId > 0) {
+            global.stage.disconnect(this._capturedEventId);
+            this._capturedEventId = 0;
+        }
+
+        if (this._eventId > 0) {
+            global.stage.disconnect(this._eventId);
+            this._eventId = 0;
+        }
+
+        if (this._keyFocusNotifyId > 0) {
+            global.stage.disconnect(this._keyFocusNotifyId);
+            this._keyFocusNotifyId = 0;
+        }
+
+        if (!this._focusWindowChanged > 0) {
+            let metaDisplay = global.screen.get_display();
+            metaDisplay.disconnect(this._focusWindowChangedId);
+            this._focusWindowChangedId = 0;
+        }
 
         let prePopInputMode = global.stage_input_mode;